<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-undefined.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="共同学习，共同进步">
<meta property="og:type" content="website">
<meta property="og:title" content="highfish920">
<meta property="og:url" content="http://example.com/index.html">
<meta property="og:site_name" content="highfish920">
<meta property="og:description" content="共同学习，共同进步">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="小鱼儿">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>highfish920</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="highfish920" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">highfish920</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <div>
      
</div>
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/05/03/Git/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="小鱼儿">
      <meta itemprop="description" content="共同学习，共同进步">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="highfish920">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/05/03/Git/" class="post-title-link" itemprop="url">git</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-05-03 00:00:00 / 修改时间：11:03:37" itemprop="dateCreated datePublished" datetime="2021-05-03T00:00:00+08:00">2021-05-03</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index"><span itemprop="name">java</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="Git"><a href="#Git" class="headerlink" title="Git"></a>Git</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">授课思路：</span><br><span class="line">	<span class="number">1.</span> 以实际开发中需要协同开发为引导 介绍Git</span><br><span class="line">	<span class="number">2.</span> 新知识的讲解一定要关注：why为什么学习Git  whatGit是什么  how怎么使用</span><br><span class="line">	<span class="number">3.</span> 讲解Git一些常见命令</span><br><span class="line">	<span class="number">4.</span> 重点讲解在Idea中如何使用Git</span><br><span class="line">注：</span><br><span class="line">	重点<span class="number">1</span>：如何在Idea中配置Git以及使用Git</span><br><span class="line">	重点<span class="number">2</span>：版本冲突的发生和解决</span><br></pre></td></tr></table></figure>



<h3 id="一、Git概述"><a href="#一、Git概述" class="headerlink" title="一、Git概述"></a>一、Git概述</h3><p>####（一）什么是Git？</p>
<blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Git是一个开源的分布式版本控制系统(Distributed Version Control System，简称DVCS)。可以有效、高速地处理从很小到非常大的项目版本管理。</span><br></pre></td></tr></table></figure>
</blockquote>
<p>####（二）什么是版本控制系统？</p>
<blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">版本控制系统能追踪项目，从开始到结束的整个过程。对编程人员而言，版本控制技术是团队协作开发的桥梁，助力于多人协作同步进行大型项目开发。软件版本控制系统的核心任务:查阅项目历史操作记录、实现协同开发。</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（三）常见的版本控制系统"><a href="#（三）常见的版本控制系统" class="headerlink" title="（三）常见的版本控制系统"></a>（三）常见的版本控制系统</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">① 集中式版本控制工具</span><br><span class="line">	集中式版本控制工具，版本仓库是集中存放在中央服务器的，team里每个人工作时，从中央 服务器下载代码。每个人个人修改后，提交到中央版本仓库。提交(commit)代码需要联网。如：svn</span><br><span class="line">	这会造成一个明显的问题：单点故障</span><br></pre></td></tr></table></figure>

<p><img src="img/jzsbbkzxt.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">② 分布式版本控制工具</span><br><span class="line">	分布式版本控制系统可以没有 “中央服务器”，每个人的电脑上都是一个完整的版本仓库，这样工作的时候，不需要联网。因为版本仓库就在你自己的电脑上。多人协作只需要各自修改，开发完成即可，推送给对方【联网】，推送的时候是将整个版本仓库推过去。如：Git</span><br></pre></td></tr></table></figure>

<p><img src="img/fbsbbkzxt.png"></p>
</blockquote>
<h4 id="（四）Git的特点"><a href="#（四）Git的特点" class="headerlink" title="（四）Git的特点"></a>（四）Git的特点</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">① 速度、简单的设计 </span><br><span class="line">② 对非线性开发模式的强力支持(允许成千上万个并行开发的分支) </span><br><span class="line">③ 完全分布式</span><br><span class="line">④ 有能力高效管理类似 Linux 内核一样的超大规模项目(速度和数据量)</span><br><span class="line">⑤ 协同开发</span><br></pre></td></tr></table></figure>

<p><img src="img/Git%E5%B7%A5%E4%BD%9C%E6%B5%81.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Clone:克隆，从远程仓库中克隆代码到本地仓库，第一次操作 </span><br><span class="line">Push:推送，代码完成后，需要和团队成员共享代码时，将代码推送到远程仓库。 </span><br><span class="line">Pull:拉取，从远程库拉代码到本地库，自动进行合并(merge)，最后放到工作区。</span><br></pre></td></tr></table></figure>



<p><img src="img/Git%E5%B7%A5%E4%BD%9C%E6%B5%812.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">checkout:将本地仓库的内容检出到工作区 </span><br><span class="line">add:在提交前先将代码提交到暂存区 </span><br><span class="line">commit:提交到本地仓库</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（五）基本概念"><a href="#（五）基本概念" class="headerlink" title="（五）基本概念"></a>（五）基本概念</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">本地仓库: 在本地主机上的一个代码库，可以独立存在，也可以与远程仓库进行关联</span><br><span class="line"></span><br><span class="line">工作区:对任何文件的修订(增删改)，都先放在工作区，工作区不与任何仓库分支进行关联 暂存区:把修订的文件，从工作区经过add(添加)后与某一个仓库分支进行关联，只要进 入缓存区的文件才能commit(提交)到本地仓库。</span><br><span class="line"></span><br><span class="line">远程仓库 : 在局域网或互联网上的一个主机，存放代码库的主机或平台，比如GitHub、 Gitee.com(码云)</span><br><span class="line"></span><br><span class="line">分支:代码存放在仓库，默认是主分支(master)，可以在主分支基础上创建很多子分支，比如 develop(开发)、bugfix(bug修复)等。</span><br></pre></td></tr></table></figure>


</blockquote>
<h3 id="二、Git的下载和安装"><a href="#二、Git的下载和安装" class="headerlink" title="二、Git的下载和安装"></a>二、Git的下载和安装</h3><p>####（一）下载</p>
<blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">下载地址：https:<span class="comment">//git-scm.com/download</span></span><br></pre></td></tr></table></figure>

<p><img src="img/Git%E4%B8%8B%E8%BD%BD.png"></p>
</blockquote>
<h4 id="（二）安装"><a href="#（二）安装" class="headerlink" title="（二）安装"></a>（二）安装</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">傻瓜式安装：一路下一步。安装完成后在电脑桌面右击显示</span><br><span class="line">注：</span><br><span class="line">	Git GUI Here：Git提供的图形界面工具</span><br><span class="line">	Git Bash Here：Git提供的命令行工具</span><br></pre></td></tr></table></figure>

<p><img src="img/Git%E5%AE%89%E8%A3%85.png"></p>
</blockquote>
<h3 id="三、Git的基本配置"><a href="#三、Git的基本配置" class="headerlink" title="三、Git的基本配置"></a>三、Git的基本配置</h3><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1.安装完成 Git 后，正式使用git前，是需要进行一些全局设置的，如用户名、邮箱。</span><br><span class="line"><span class="comment"># 设置全局用户名</span></span><br><span class="line">git config --global user.name <span class="string">&quot;your name&quot;</span></span><br><span class="line"><span class="comment"># 设置邮箱</span></span><br><span class="line">git config --global user.email <span class="string">&quot;your email&quot;</span></span><br></pre></td></tr></table></figure>

<p><img src="img/%E6%9C%AC%E5%9C%B0%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">	以上配置信息默认存储在用户目录下，如果设置错误，可以删除以下如图文件，重新操作以上命令即</span><br><span class="line">可。</span><br></pre></td></tr></table></figure>

<p><img src="img/Git%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6.png"></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">2. 查看配置信息：git config --list</span><br></pre></td></tr></table></figure>

<p><img src="img/%E6%9F%A5%E7%9C%8B%E9%85%8D%E7%BD%AE%E4%BF%A1%E6%81%AF.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">3.</span> 构建本地仓库：要使用Git对我们的代码进行版本控制，首先需要构建本地仓库</span><br><span class="line">	① 在本地初始化一个Git仓库</span><br><span class="line">	② 从远程仓库克隆一个仓库</span><br></pre></td></tr></table></figure>
</blockquote>
<blockquote>
<p>####本地仓库的相关操作</p>
</blockquote>
<blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 在本地初始化一个Git仓库:</span><br><span class="line">	- 在电脑的任意位置创建一个空目录作为我们的本地Git仓库</span><br><span class="line">	- 进入这个目录中，点击右键打开Git bash窗口</span><br><span class="line">	- 执行命令Git init </span><br><span class="line">		如果在当前目录中看到.git文件夹(此文件夹为隐藏文件夹)则说明Git仓库创建成功</span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">2. 查看文件状态：</span><br><span class="line">	git status [-s]</span><br></pre></td></tr></table></figure>

<p><img src="img/%E6%9F%A5%E7%9C%8B%E7%8A%B6%E6%80%81.png"></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">3. 将文件添加(修改)到版本库</span><br><span class="line">	要将一个文件纳入到版本库管理，首先要将其添加到暂存区，然后才能提交到仓库中。</span><br><span class="line">	<span class="comment"># 添加单个文件到暂存区</span></span><br><span class="line">	git add Readme.txt</span><br><span class="line">	<span class="comment"># 将当前目录下所有修改添加到暂存区，除按照规则忽略的之外 </span></span><br><span class="line">	git add .</span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">4. 将暂存区中的文件，提交到仓库中</span><br><span class="line">	<span class="comment"># 如果暂存区有文件，则将其中的文件提交到仓库 </span></span><br><span class="line">	git commit</span><br><span class="line">	<span class="comment"># 带评论提交，用于说明提交内容、变更、作用等 </span></span><br><span class="line">	git commit -m <span class="string">&#x27;your comments&#x27;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">5. 查看提交历史记录</span><br><span class="line">	有的时候，是会需要查看自己做过哪些提交，来回顾自己完成的部分。或者需要寻找某个具体的提交来</span><br><span class="line">查看当时的代码。</span><br><span class="line">	git <span class="built_in">log</span> <span class="comment"># 显示所有提交的历史记录</span></span><br><span class="line">	git <span class="built_in">log</span> --pretty=oneline <span class="comment"># 单行显示提交历史记录的内容</span></span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">6. 版本回退</span><br><span class="line">	有了 git <span class="built_in">log</span> 来查看提交的历史记录，我们就可以通过 git reset --hard 来回退到我们需要的特定版本，然后使用当时的代码进行各种操作。</span><br><span class="line">	<span class="comment"># 回退到 commit_id 指定的提交版本 </span></span><br><span class="line">	git reset --hard <span class="string">&#x27;commit_id&#x27;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">7. 回到未来的某个提交</span><br><span class="line">	当退回到某个提交的版本以后，再通过 git <span class="built_in">log</span> 是无法显示在这之后的提交信息的。但是，通过 git reflog 可以获取到操作命令的历史。因此，想要回到未来的某个提交，先通过 git reflog 从历史命令中找到想要回到的提交版本的 ID， 然后通过 git reset --hard 来切换。</span><br><span class="line">	git reflog</span><br><span class="line">	git reset --hard <span class="string">&#x27;commit_id&#x27;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">8. 删除文件</span><br><span class="line">	在文件未添加到暂存区之前，对想删除文件可以直接物理删除。如果文件已经被提交，则需要 git rm</span><br><span class="line">来删除</span><br><span class="line">	git rm Readme.txt // 删除已经被提交过的 Readme.txt</span><br><span class="line">注意: git rm 只能删除已经提交到版本库中的文件。其他状态的文件直接用这个命令操作是出错的。</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">9. 添加文件至忽略列表</span><br><span class="line">	一般在工作区中，并不是所有文件都需要纳入版本控制的。这种不需要进行版本控制的通常都是些自动生成的文件。比如:idea工程文件(springmvc.iml)、编译后 文件target、系统上传的图片img。在这种情况下，我们可以在工作目录中创建一个名为 .gitignore 的文件(文件名称固定)，列出要忽略的文件。</span><br><span class="line">	</span><br></pre></td></tr></table></figure>


</blockquote>
<h3 id="四、分支管理"><a href="#四、分支管理" class="headerlink" title="四、分支管理"></a>四、分支管理</h3><h4 id="（一）查看分支"><a href="#（一）查看分支" class="headerlink" title="（一）查看分支"></a>（一）查看分支</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看本地分支信息</span></span><br><span class="line">git branch</span><br><span class="line"><span class="comment"># 查看相对详细的本地分支信息 </span></span><br><span class="line">git branch -v</span><br><span class="line"><span class="comment"># 查看包括远程仓库在内的分支信息 </span></span><br><span class="line">git branch -av</span><br><span class="line"></span><br><span class="line">注意：前面带有*号，这标识我们当前所在的分支</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（二）创建分支"><a href="#（二）创建分支" class="headerlink" title="（二）创建分支"></a>（二）创建分支</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 新建一个名称为 dev 的分支 </span></span><br><span class="line">git branch dev</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（三）切换分支"><a href="#（三）切换分支" class="headerlink" title="（三）切换分支"></a>（三）切换分支</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 新建完 dev 分支以后，通过该命令切换到 dev 分支 </span></span><br><span class="line">git checkout dev</span><br><span class="line">注意：当我们创建完分支以后，我们需要切换到新建的分支，否则，所有的修改，还是在原来的分支上。事实上，所有的改动，只能影响到当前所在的分支。</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（四）创建并切换分支"><a href="#（四）创建并切换分支" class="headerlink" title="（四）创建并切换分支"></a>（四）创建并切换分支</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 新建 dev 分支，并切换到该分支上 </span></span><br><span class="line">git checkout -b dev</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（五）合并分支"><a href="#（五）合并分支" class="headerlink" title="（五）合并分支"></a>（五）合并分支</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 切换回 master 分支</span></span><br><span class="line">git checkout master</span><br><span class="line"><span class="comment"># 将 dev 分支中的修改合并回 master 分支 </span></span><br><span class="line">git merge dev</span><br><span class="line">注意：分支修改文件中如果有换行的话会报错</span><br></pre></td></tr></table></figure>

<p><img src="img/%E5%88%86%E6%94%AF%E6%93%8D%E4%BD%9C.png"></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">解决：Git默认配置替换回车换行成统一的CRLF，我们只需要修改配置禁用该功能即可。</span><br><span class="line">git config --global core.autocrlf <span class="literal">false</span></span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（六）删除分支"><a href="#（六）删除分支" class="headerlink" title="（六）删除分支"></a>（六）删除分支</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">	当之前创建的分支，完成了它的使命，如 Bug 修复完，分支合并以后，这个分支就不在需要了，就可 以删除它。</span><br><span class="line"><span class="comment"># 删除dev分支 </span></span><br><span class="line">git branch -d dev</span><br></pre></td></tr></table></figure>


</blockquote>
<h3 id="五、远程仓库"><a href="#五、远程仓库" class="headerlink" title="五、远程仓库"></a>五、远程仓库</h3><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">现在我们已经在本地创建了一个Git仓库，又想让其他人来协作开发，此时就可以把本地仓库同步到远 程仓库，同时还增加了本地仓库的一个备份。那么我们如何搭建Git远程仓库呢?我们可以借助互联网上提供的一些代码托管服务平台来实现，其中 比较常用的有GitHub、码云等。</span><br><span class="line">-- GitHub( 地址:https:<span class="comment">//github.com/ )是一个面向开源及私有软件项目的托管平台，因为只支持 Git 作为唯一的版本仓库格式进行托管，故名GitHub。</span></span><br><span class="line">-- 码云(地址: https:<span class="comment">//gitee.com/ )是国内的一个代码托管平台，由于服务器在国内，所以相比于 GitHub，码云速度会更快。</span></span><br><span class="line">接下来我们演示如何将本地仓库中的代码同步到github。和码云的操作一模一样</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（一）注册账号"><a href="#（一）注册账号" class="headerlink" title="（一）注册账号"></a>（一）注册账号</h4><blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">① 第一步，点击注册按钮</span><br></pre></td></tr></table></figure>

<p><img src="img/github01.png"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">② 填写真实信息</span><br></pre></td></tr></table></figure>

<p><img src="img/github%E6%B3%A8%E5%86%8C.png"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">③ 邮箱验证</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="（二）登录使用"><a href="#（二）登录使用" class="headerlink" title="（二）登录使用"></a>（二）登录使用</h4><blockquote>
<p><img src="img/github%E7%99%BB%E5%BD%95.png"></p>
<p><img src="img/%E5%88%9B%E5%BB%BA%E4%BB%93%E5%BA%93.png"></p>
<p><img src="img/%E4%BB%93%E5%BA%93.png"></p>
</blockquote>
<h3 id="六、同步远程仓库"><a href="#六、同步远程仓库" class="headerlink" title="六、同步远程仓库"></a>六、同步远程仓库</h3><blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Github支持两种同步方式“https”和“ssh”。如果使用https很简单基本不需要配置就可以使用，但是每次 提交代码和下载代码时都需要输入用户名和密码。而且如果是公司配置的私有git服务器一般不提供 https方式访问，所以我们要来着重演示“ssh”方式。</span><br></pre></td></tr></table></figure>

<p><img src="img/%E8%BF%9C%E7%A8%8B%E5%9C%B0%E5%9D%80.png"></p>
</blockquote>
<h4 id="（一）https克隆"><a href="#（一）https克隆" class="headerlink" title="（一）https克隆"></a>（一）https克隆</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">命令：git <span class="built_in">clone</span> https地址</span><br></pre></td></tr></table></figure>


</blockquote>
<p>####（二）ssh配置</p>
<blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SSH是英文Secure Shell的简写形式。通过使用SSH，你可以把所有传输的数据进行加密，这样<span class="string">&quot;中间 人&quot;</span>这种攻击方式就不可能实现了，而且也能够防止DNS欺骗和IP欺骗。使用SSH，还有一个额外的好处 就是传输的数据是经过压缩的，所以可以加快传输的速度。</span><br><span class="line">注：使用SSH同步方式需要先生成密钥并在GitHub配置公钥</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">执行命令,生成公钥和私钥:</span><br><span class="line">	ssh-keygen -t rsa</span><br><span class="line">执行命令完成后,在window本地用户.ssh目录C:\Users\用户名.ssh下面生成如下名称的公钥和私钥</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">密钥生成后需要在github上配置密钥，本地才可以顺利访问。</span><br></pre></td></tr></table></figure>

<p><img src="img/ssh%E9%85%8D%E7%BD%AE1.png"></p>
<p><img src="img/ssh%E9%85%8D%E7%BD%AE2.png"></p>
<p><img src="img/ssh%E9%85%8D%E7%BD%AE3.png"></p>
</blockquote>
<h3 id="七、远程仓库的操作"><a href="#七、远程仓库的操作" class="headerlink" title="七、远程仓库的操作"></a>七、远程仓库的操作</h3><h4 id="（一）查看远程仓库"><a href="#（一）查看远程仓库" class="headerlink" title="（一）查看远程仓库"></a>（一）查看远程仓库</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">如果想查看已经配置的远程仓库服务器，可以运行 git remote 命令。 它会列出指定的每一个远程服务 器的简写。 如果已经克隆了远程仓库，那么至少应该能看到 origin ，这是 Git 克隆的仓库服务器的默 认名字</span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 命令形式:</span></span><br><span class="line">git remote -v</span><br><span class="line"><span class="comment"># origin ——仓库服务器的默认名称</span></span><br><span class="line">注：如果显示空，没有添加远程仓库。如果添加显示远程仓库地址</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（二）添加远程仓库"><a href="#（二）添加远程仓库" class="headerlink" title="（二）添加远程仓库"></a>（二）添加远程仓库</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">如果已经有了一个本地仓库，，然后打算将它发布到远程，供其他人协作。</span><br><span class="line">那么使用命令：</span><br><span class="line"><span class="comment"># 为本地仓库添加远程仓库</span></span><br><span class="line">git remote add origin 远程仓库地址</span><br><span class="line">如：git remote add origin https://gitee.com/junguang00/git_demo01.git</span><br><span class="line"></span><br><span class="line">注：</span><br><span class="line">	 提示出错信息：fatal: remote origin already exists.</span><br><span class="line">	 先输入</span><br><span class="line">	 	$ git remote rm origin</span><br><span class="line">	 再输入：</span><br><span class="line">	 	git remote add origin 远程仓库地址</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（三）推送本地内容到远程仓库"><a href="#（三）推送本地内容到远程仓库" class="headerlink" title="（三）推送本地内容到远程仓库"></a>（三）推送本地内容到远程仓库</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在本地仓库更新内容 添加暂存区</span></span><br><span class="line">git add .</span><br><span class="line"><span class="comment"># 提交内容</span></span><br><span class="line">git commit -m <span class="string">&#x27;信息&#x27;</span></span><br><span class="line"><span class="comment"># 当本地仓库中，代码完成提交，就需要将代码等推送到远程仓库，这样其他协作人员可以从远程仓库同步内容。</span></span><br><span class="line"><span class="comment"># 第一次推送时使用，可以简化后面的推送或者拉取命令使用 </span></span><br><span class="line">git push -u origin master</span><br><span class="line"><span class="comment"># 将本地 master 分支推送到 origin 远程分支</span></span><br><span class="line">git push origin master</span><br><span class="line">	注意: </span><br><span class="line">		① git push -u origin master ，第一次使用时，带上 -u 参数，在将本地的 master 分支推送 到远程新的 master 分支的同时，还会把本地的 master 分支和远程的 master 分支关联起来。</span><br><span class="line">		② 推送之前，需要先pull远端仓库，如果发现提交版本不一致，出现错误</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（四）"><a href="#（四）" class="headerlink" title="（四）"></a>（四）</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">	在多人协作过程中，当自己完成了本地仓库中的提交，想要向远程仓库推送前，需要先获取到远程仓库的最新内容。使用如下命令</span><br><span class="line">	git fetch origin master</span><br><span class="line">	git pull origin master</span><br><span class="line">git fetch 和 git pull 之间的区别:</span><br><span class="line">	git fetch 是仅仅获取远程仓库的更新内容，并不会自动做合并。</span><br><span class="line">	git pull 在获取远程仓库的内容后，会自动做合并，可以看成 git fetch 之后 git merge 。</span><br><span class="line"></span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（五）移除无效的远程仓库"><a href="#（五）移除无效的远程仓库" class="headerlink" title="（五）移除无效的远程仓库"></a>（五）移除无效的远程仓库</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 命令形式: </span></span><br><span class="line">git remote rm &lt;shortname&gt;</span><br><span class="line">注意:此命令只是从本地移除远程仓库的记录，并不会真正影响到远程仓库</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（六）从远程仓库克隆"><a href="#（六）从远程仓库克隆" class="headerlink" title="（六）从远程仓库克隆"></a>（六）从远程仓库克隆</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Git 克隆的是该 Git 仓 库服务器上的几乎所有数据(包括日志信息、历史记录等)，而不仅仅是复制工作所需要的文件。 当你 执行 git <span class="built_in">clone</span> 命令的时候，默认配置下远程 Git 仓库中的每一个文件的每一个版本都将被拉取下来。</span><br><span class="line">如果你本地没有仓库，希望从已有的远程仓库上复制一份代码，那么你需要 git <span class="built_in">clone</span> 。</span><br><span class="line"><span class="comment"># 通过 https 协议，克隆 Github 上 git 仓库的源码</span></span><br><span class="line">git <span class="built_in">clone</span> https://github.com/lagou-zimu/repo1.git </span><br><span class="line"><span class="comment"># 通过 ssh 协议，克隆 Github 上 git 仓库的源码</span></span><br><span class="line">git <span class="built_in">clone</span> git@github.com:lagou-zimu/repo1.git</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（七）从远程仓库中拉取"><a href="#（七）从远程仓库中拉取" class="headerlink" title="（七）从远程仓库中拉取"></a>（七）从远程仓库中拉取</h4><blockquote>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"># 拉取 命令形式:git pull【远程仓库名称】【分支名称】</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（八）解决合并冲突"><a href="#（八）解决合并冲突" class="headerlink" title="（八）解决合并冲突"></a>（八）解决合并冲突</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">在一段时间，A、B用户修改了同一个文件，且修改了同一行位置的代码，此时会发生合并冲突。</span><br><span class="line">例如：</span><br><span class="line">	A用户在本地修改代码后优先推送到远程仓库，此时B用户在本地修订代码，提交到本地仓库后，也需 要推送到远程仓库，此时B用户晚于A用户推送，故需要先拉取远程仓库代码，经过合并后才能推送代 码。在B用户拉取代码时，因为A、B用户同一段时间修改了同一个文件的相同位置代码，故会发生合并 冲突。</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">解决：</span><br><span class="line">	① 先拉取代码</span><br><span class="line">	② 打开代码解决冲突</span><br><span class="line">	③ 再提交</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（九）小结"><a href="#（九）小结" class="headerlink" title="（九）小结"></a>（九）小结</h4><blockquote>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">远程仓库常见操作命令：</span><br><span class="line">git remote <span class="comment">#查看所有远程仓库名称</span></span><br><span class="line">git remote -v <span class="comment">#查看远程仓库缩略信息</span></span><br><span class="line">git push origin master <span class="comment"># 将本地仓库代码推送到远程仓库</span></span><br><span class="line">git <span class="built_in">clone</span> https://github.com/lagou-zimu/repo1.git <span class="comment"># 克隆远程仓库代码到本地 git pull origin master # 拉取远程仓库代码到本地:(fetch+merge)</span></span><br></pre></td></tr></table></figure>


</blockquote>
<h3 id="八、Idea中集成Git"><a href="#八、Idea中集成Git" class="headerlink" title="八、Idea中集成Git"></a>八、Idea中集成Git</h3><h4 id="（一）在idea中配置Git"><a href="#（一）在idea中配置Git" class="headerlink" title="（一）在idea中配置Git"></a>（一）在idea中配置Git</h4><blockquote>
<p><img src="img/idea%E9%85%8D%E7%BD%AEGit.png"></p>
</blockquote>
<h4 id="（二）Idea的Git操作"><a href="#（二）Idea的Git操作" class="headerlink" title="（二）Idea的Git操作"></a>（二）Idea的Git操作</h4><p>#####1. 初始化并提交项目到远程仓库 【项目leader操作】</p>
<blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">① 初始化并提交项目到远程仓库 【项目leader操作】</span><br><span class="line">执行步骤:</span><br><span class="line">	<span class="number">1.</span> 在GitHub/码云中创建远程仓库 </span><br><span class="line">	<span class="number">2.</span> 将工程交给Git管理</span><br><span class="line">	<span class="number">3.</span> 配置忽略文件</span><br><span class="line">	<span class="number">4.</span> 提交到本地仓库</span><br><span class="line">	<span class="number">5.</span> 推送到远程仓库</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">② 在github上创建仓库</span><br></pre></td></tr></table></figure>

<p><img src="img/%E4%BB%93%E5%BA%93.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">③ 将工程交给Git管理</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E4%B8%ADGit%E4%BD%BF%E7%94%A81.png"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">④ 配置忽略文件</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E9%85%8D%E7%BD%AE%E5%BF%BD%E7%95%A5%E6%96%87%E4%BB%B6.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">⑤ 提交到本地仓库</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E6%8F%90%E4%BA%A4%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93.png"></p>
<p><img src="img/idea%E6%8F%90%E4%BA%A4.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">⑥ 推送到远程仓库</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E6%8E%A8%E9%80%81%E8%BF%9C%E7%A8%8B.png"></p>
<p><img src="img/idea%E6%8F%90%E4%BA%A4%E8%BF%9C%E7%A8%8B%E5%9C%B0%E5%9D%80.png"></p>
</blockquote>
<h5 id="2-克隆远程仓库到本地【开发人员】"><a href="#2-克隆远程仓库到本地【开发人员】" class="headerlink" title="2. 克隆远程仓库到本地【开发人员】"></a>2. 克隆远程仓库到本地【开发人员】</h5><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">① 从远程仓库克隆</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E5%85%8B%E9%9A%86.png"></p>
<p><img src="img/idea%E5%85%8B%E9%9A%86Git.png"></p>
</blockquote>
<h4 id="（三）Idea中Git的常见操作【开发人员重点】"><a href="#（三）Idea中Git的常见操作【开发人员重点】" class="headerlink" title="（三）Idea中Git的常见操作【开发人员重点】"></a>（三）Idea中Git的常见操作【开发人员重点】</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">① 新增文件：新文件状态红色，未进入暂存区</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E6%96%B0%E5%A2%9E%E6%96%87%E4%BB%B6.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">加入git之后，红色变绿色，已经进入暂存区</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E8%BF%9B%E5%85%A5%E6%9A%82%E5%AD%98%E5%8C%BA.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">② 编辑文件：修改文件 变成蓝色</span><br><span class="line">正常编辑的文件默认放在暂存区，不需要再添加到暂存区</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">③ 重置文件到修改前</span><br><span class="line">比如修订了某一文件，需要重置到修改文件之前的状态，选择文件，右键菜单:选择Git---&gt;Revert</span><br><span class="line">重置后，文件颜色自动消失，说明已重置到修改之前的状态。</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E8%BF%94%E5%9B%9E%E4%BF%AE%E6%94%B9%E5%89%8D.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">④ 提交当前文件</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">⑤ 本地仓库推送到远程仓库</span><br><span class="line">操作步骤:</span><br><span class="line">	<span class="number">1.</span> 推送前一定要先拉取远程仓库对应分支</span><br><span class="line">	<span class="number">2.</span> 如果有冲突，先解决冲突，并提交到本地仓库 </span><br><span class="line">	<span class="number">3.</span> 推送当前分支到远程仓库</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">冲突：如果A、B两个分支都在操作同一文件。当A分支提交远程仓库之后，B分支再提交的话会产生冲突</span><br><span class="line">解决：先拉取，解决完冲突，再push</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E6%8B%89%E5%8F%96.png"></p>
<p><img src="img/idea%E7%89%88%E6%9C%AC%E5%86%B2%E7%AA%811.png"></p>
<p><img src="img/idea%E7%89%88%E6%9C%AC%E5%86%B2%E7%AA%812.png"></p>
<p><img src="img/idea%E7%89%88%E6%9C%AC%E5%86%B2%E7%AA%813.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">再推送到远程仓库</span><br></pre></td></tr></table></figure>


</blockquote>
<h4 id="（四）分支操作"><a href="#（四）分支操作" class="headerlink" title="（四）分支操作"></a>（四）分支操作</h4><blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">操作步骤:</span><br><span class="line">	<span class="number">1.</span> 创建分支</span><br><span class="line">	<span class="number">2.</span> 切换分支执行操作</span><br><span class="line">	<span class="number">3.</span> 执行合并操作，master合并dev</span><br><span class="line">	<span class="number">4.</span> 同步远程仓库</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">① 创建分支</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF1.png"></p>
<p><img src="img/%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF.gif"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">② 切换分支执行操作</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">③ 执行合并操作(将dev分支合并到master分支)</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E5%88%87%E5%9B%9Emaster.gif"></p>
<p><img src="img/idea%E5%90%88%E5%B9%B6%E5%88%86%E6%94%AF.png"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">④ 同步远程仓库</span><br></pre></td></tr></table></figure>

<p><img src="img/idea%E5%90%88%E5%B9%B6%E5%90%8E%E4%B8%8A%E4%BC%A0.gif"></p>
</blockquote>
<h4 id="（五）查看提交历史提交"><a href="#（五）查看提交历史提交" class="headerlink" title="（五）查看提交历史提交"></a>（五）查看提交历史提交</h4><blockquote>
<p>​    <img src="img/idea%E6%9F%A5%E7%9C%8B%E5%8E%86%E5%8F%B2.png"></p>
<p><img src="img/idea%E6%98%BE%E7%A4%BA%E5%8E%86%E5%8F%B2.png"></p>
</blockquote>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">小鱼儿</p>
  <div class="site-description" itemprop="description">共同学习，共同进步</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">1</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/highfish920" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;highfish920" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/weixin_42693712?spm=1000.2115.3001.5343" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;weixin_42693712?spm&#x3D;1000.2115.3001.5343" rel="noopener" target="_blank"><i class="fa fa-book fa-fw"></i>CSDN</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小鱼儿</span>
</div>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="powered-by">
  <i class="fa fa-user-md"></i>
  <span id="busuanzi_container_site_pv">
    本站访问量:<span id="busuanzi_value_site_pv"></span>次
  </span>
  <span class="post-meta-divider">|</span>
  <span id="busuanzi_container_site_uv">
    本站总访客量：<span id="busuanzi_value_site_uv"></span>人
  </span>
</div>

 <span class="post-meta-divider">|</span>

<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共4.5k字</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<a target="_blank" rel="noopener" href="https://github.com/highfish920" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  
</body>
</html>
